﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;

namespace winform基础学习
{
    public partial class RegisterForm : Form
    {
        public RegisterForm()
        {
            InitializeComponent();
        }


        private void Login_Click(object sender, EventArgs e)
        {
            //获取用户名
            string userName = username.Text;
            //获取密码 确定密码
            string passWord = password.Text;
            string passWord2 = password2.Text;
            if (passWord != passWord2)
            {
                MessageBox.Show("两次密码不一样!");
                return;
            }
            //获取昵称
            string nickName = nickname.Text;

            //获取性别
            string sex = null;
            if (radioButton1.Checked)
            {
                sex = "男";
            }
            else
            {
                sex = "女";
            }

            UserTModel userTModel = new UserTModel();
            userTModel.UserName = userName;
            userTModel.PassWord = passWord;
            userTModel.NickName = nickName;
            userTModel.Sex = sex;
            int i = 0;
            using (MyDbContext dbContext = new MyDbContext())
            {
                dbContext.userTModels.Attach(userTModel);
                dbContext.Entry(userTModel).State = System.Data.Entity.EntityState.Added;
                i = dbContext.SaveChanges();
            }
            if (i <= 0)
            {
                MessageBox.Show("注册失败!");
            }
            else
            {
                MessageBox.Show("注册成功!");
                this.Close();
            }
        }
    }
}
